package com.mak.menoy.widget;


import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mak.menoy.R;

public class RequestDialog extends CustomDialog {
	private ImageView loadingIcon;
	private String title;
	private Context mContext;
	
	private LinearLayout cancleLayout;
	
	public RequestDialog(Context context, String title) {
		super(context);
		this.title = title;
		init(context);
		mContext=context;
	}
	
	public RequestDialog(Context context, DialogInterface.OnCancelListener listener) {
		super(context, listener);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.request_dialog, null);
//		view.getBackground().setAlpha(90);
		if (title != null) {
			TextView text = (TextView) view.findViewById(R.id.loading_title);
			text.setText(title);
		}
		loadingIcon = (ImageView) view.findViewById(R.id.loading_icon);
		cancleLayout=(LinearLayout) view.findViewById(R.id.load_cancle);
		addContentView(view, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		cancleLayout.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				cancel();
				
			}
		});
	}
	
	

	@Override
	public void show() {
		super.show();
		loadingIcon.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.rotate_image));
	}

	@Override
	public void cancel() {
		super.cancel();
		loadingIcon.clearAnimation();
		
//		 Activity activity=(Activity) mContext;
//		 activity.finish();
		 
		
	}
	
	
}
